/*
429. N 叉树的层序遍历
https://leetcode.cn/problems/n-ary-tree-level-order-traversal/description/
中等 2024/12/04
*/

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
vector<vector<int>>arr;

void test(Node* root)
{
    if(root==NULL) return ;
    queue<Node* >q;
    q.push(root);
    while(!q.empty())
    {
        vector<int>crr;
        int n=q.size();
        for(int i=0;i<n;i++)
        {
            vector<Node*>ans=q.front()->children;
            crr.push_back(q.front()->val);
            q.pop();
            for(int j=0;j<ans.size();j++)
            {
                if(ans[j])
                q.push(ans[j]);                
            }
        }
        arr.push_back(crr);
    }
}
    vector<vector<int>> levelOrder(Node* root) {
        test(root);
        return arr;
    }
};